package com.wx.mall.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wx.mall.common.vo.goods.SkuVo;
import com.wx.mall.feign.GoodListFeignClient;
import com.wx.mall.order.dto.ReOrderDto;
import com.wx.mall.order.entity.ReturnOrder;
import com.wx.mall.order.entity.ReturnOrderAddress;
import com.wx.mall.order.entity.ReturnOrderItem;
import com.wx.mall.order.mapper.ReturnOrderItemMapper;
import com.wx.mall.order.service.IReturnOrderAddressService;
import com.wx.mall.order.service.IReturnOrderItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wx.mall.order.service.IReturnOrderService;
import com.wx.mall.order.vo.GoodReturnItemVo;
import com.wx.mall.order.vo.GoodReturnVo;
import com.wx.mall.order.vo.ReturnOrderItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 退款订单项 服务实现类
 * </p>
 *
 * @author j
 * @since 2020-05-09
 */
@Service
public class
ReturnOrderItemServiceImpl extends ServiceImpl<ReturnOrderItemMapper, ReturnOrderItem> implements IReturnOrderItemService {

    @Autowired
    GoodListFeignClient skuData;

    @Autowired
    IReturnOrderService service;

    @Autowired
    IReturnOrderAddressService iReturnOrderAddressService;

    @Override
    public List<GoodReturnItemVo> getFindGood(GoodReturnVo ids) {
        List<GoodReturnItemVo> list=new ArrayList<>();
        for (Long id:ids.getIds()
        ) {
            GoodReturnItemVo all=new GoodReturnItemVo();
            QueryWrapper<ReturnOrderItem> wrapper1=new QueryWrapper();
            wrapper1.eq("return_order_id",id);
            List<ReturnOrderItem> list1=this.list(wrapper1);
            List<ReturnOrderItemVo> list2= JSON.parseArray(JSON.toJSONString(list1),ReturnOrderItemVo.class);
            for (ReturnOrderItemVo vo:list2
                 ) {
                SkuVo skuVo = skuData.listById(vo.getSkuId());
                vo.setSkuVo(skuVo);
            }
            ReturnOrder byId = service.getById(id);
            ReturnOrderAddress byId1 = iReturnOrderAddressService.getById(id);
            all.setReturnOrder(byId);
            all.setList(list2);
            all.setReturnOrderAddress(byId1);
            list.add(all);
        }
        return list;
    }
}
